﻿using System.IO;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TrackIT.Common.Factories;

namespace TrackIT.UnitTest.Factories
{
    [TestClass]
    public class WorkStreamFactoryTest
    {
        [TestMethod]
        [DeploymentItem("DeploymentItems\\WorkLog.txt")]
        public void CreateStream_FileExists_StreamWritable()
        {
            string rootFolder = HelperUtil.ExtractPath(Assembly.GetExecutingAssembly().Location);
            string filename = Path.Combine(rootFolder, "WorkLog.txt");

            WorkStreamFactory target = new WorkStreamFactory();
            Stream actual = target.CreateStream(filename);
            Assert.IsTrue(actual.CanWrite);
            Assert.AreEqual(158, actual.Length);
        }

        [TestMethod]
        public void CreateStream_FileNotExists_StreamWritable()
        {
            string rootFolder = HelperUtil.ExtractPath(Assembly.GetExecutingAssembly().Location);
            string filename = Path.Combine(rootFolder, "WorkLog2.txt");

            WorkStreamFactory target = new WorkStreamFactory();
            Stream actual = target.CreateStream(filename);
            Assert.IsTrue(actual.CanWrite);
            Assert.AreEqual(0, actual.Length);
        }
    }
}
